import { createStore } from 'vuex';
import path from "path"
import { ESTORE_KEY } from '@/constants/constants';
import { storeSet } from "@/util/configStore";
import { toRaw } from 'vue';
import _ from "lodash";
import { formatNow } from '@/util/commonUtil';

export default createStore({
  state() {
    return {
      settings: {
        activeTab: '',
      },
    }
  },
  // mutation是同步的
  mutations: {
    // just update, don't save to file
    updateSetting(state, payload) {
      if (!payload) payload = {};
      if (!payload.activeTab) {
        payload.activeTab = 'tcpClient';
      }
      state.settings = payload;
    },
    // update and save to file
    saveSetting(state, payload) {
      this.commit("updateSetting", payload);
      storeSet(ESTORE_KEY.SYSTEM_SETTING, payload);
    },
    updateActiveTab(state, payload) {
      state.settings.activeTab = payload;
      this.commit("saveSetting", state.settings);
    }
  },
  modules: {}
})
